//
//  YHKTabBar.m
//  微博oc
//
//  Created by 杨和逵 on 16/3/15.
//  Copyright © 2016年 yanghekui. All rights reserved.
//

#import "YHKTabBar.h"

@interface YHKTabBar ()

@property (nonatomic,weak) UIButton *myButton;



@end


@implementation YHKTabBar

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self == [super initWithFrame:frame]) {
        
         //创建视图
        [self addButton];
        
    }
    
    
    
    return self;
}



//添加控件
- (void)addButton{
    
    UIButton * btn = [[UIButton alloc]init];
    
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateSelected];
    
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];
    
    [btn sizeToFit];

    //赋值
    self.myButton = btn;
    
    [self addSubview:btn ];
    

    
}


- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    CGFloat W = self.bounds.size.width / 5;
    CGFloat H = self.bounds.size.height;
    int index = 0;
 
  
 
    //遍历
    for (UIView * subview in self.subviews) {
        
        //判断是否是UITabBarButton
        if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            //设置UITabBarButton位置
            subview.frame = CGRectMake( ((index ++) * W), 0, W, H);
            
            NSLog(@"%zd",index);
            
            //空出中间那个位置来
            if (index == 2) {index ++;}
            
            
        }
    }
        
      //设置自定义的btn的frame
    self.myButton.frame = CGRectMake(W * 2, 0, W, H);
   
    
}



@end
